﻿using System;

namespace H.Utils
{
    public class RandomUtil
    {
        /// <summary>
        /// 获取一个0~1之间的随机数
        /// </summary>
        /// <returns>返回一个从0~1之间的随机数</returns>
        public static double Next()
        {
            return (DateTime.Now.Ticks * 9301 + 49297) % 233280 / 233280.0f;
        }

        /// <summary>
        /// 获取一个从0-max之间的随机数
        /// </summary>
        /// <param name="max"></param>
        /// <returns></returns>
        public static int Next(int max)
        {
            return (int)Math.Round(Next() * max);
        }

        /// <summary>
        /// 获取一个取值范围在min-max之间的随机数
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static int Next(int min, int max)
        {
            return min + (int)Math.Round(Next() * (max - min));
        }
    }
}
